package cn.com.elite.workorder;

import mlink.esms.api.simpleclient.SimpleClientExample;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import cn.com.elite.util.*;
import cn.com.elite.workorder.*;
import java.util.*;

import org.apache.struts.upload.FormFile;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

public class WorkOrderAction extends NonSessionAction {
	private static final Log log=LogFactory.getLog(WorkOrderAction.class);
	private cn.com.elite.workorder.WorkOrderBean workorderBean;

	public WorkOrderAction() {
	}

	public WorkOrderBean getWorkorderBean() {
		return workorderBean;
	}

	public void setWorkorderBean(WorkOrderBean workorderBean) {
		this.workorderBean = workorderBean;
	}

	public ActionForward sendSMS(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		WorkOrderActionForm actionForm = (WorkOrderActionForm) form;

		/*
			 ����	Ҫ��	����	��ע
			user	��ѡ	�˺���	�ʺţ���Ҫ����
			pwd	��ѡ	����	��¼����
			mobile	��ѡ	�ֻ����	����Ϣ�����ֻ����50����룬Ӣ�Ķ��ŷָ�
			����POST��ʽ������û������
			message	��ѡ	�·�����Ϣ����	����Ϣ����URL���롣�����ֲ�����70���Ӣ�Ĳ�����140������Ϣ�߶���è,116���ֽ�.
			msgid	��ѡ	��Ϣ��ʶ	�Զ��壬���ڶ�ȡ��Ϣ״̬����Ϊ������Ϊ����Ҫ״̬����
			����45���ַ����ڣ�ʱ��Ϳ���
		 */
		String user = Util.filter(request.getParameter("user"));
		String pwd = Util.filter(request.getParameter("pwd"));
		String mobile = Util.filter(request.getParameter("mobile"));
		String message = Util.filter(request.getParameter("message"));
		String msgid = Util.filter(request.getParameter("msgid"));

		System.out.println("---message=" + message);
		log.info("---message=" + message);
		String url = "http://127.0.0.1:8080/SMS/index.jsp?user=";
		url = WORKORDERFRAME.SENDSMSURL + "?user=" + java.net.URLEncoder.encode(user) + "&pwd=" + pwd
				+ "&mobile=" + mobile + "&message=" + java.net.URLEncoder.encode(message) + "&msgid=" + msgid;
		System.out.println("---url=" + url);
		log.info("---url=" + url);
		URLConnection conn = null;
		OutputStreamWriter out = null;
		try {
			URL realUrl = new URL(url);
			conn = realUrl.openConnection();
			conn.setRequestProperty("accept", "*/*");
			conn.setRequestProperty("connection", "Keep-Alive");
			conn.setRequestProperty("user-agent",
					"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
			conn.connect();

			String result = "";
			BufferedReader in = new BufferedReader(new InputStreamReader(conn
					.getInputStream()));
			String line;
			while ((line = in.readLine()) != null) {
				result += "\n" + line;
			}
			in.close();
			System.out.println("result=" + result);
			log.info("result=" + result);
			if(result.equals("0")){
				//���ŷ��ͳɹ�����ʱȡ����״̬
				Thread.sleep(Long.valueOf(WORKORDERFRAME.QUERYSMSSTATUSTIME));
				int icount = Integer.parseInt(WORKORDERFRAME.QUERYSMSSTATUSCOUNT);
				for(int i=0; i<icount; i++){
					String sendresult = inquerystatus(user, pwd, msgid);
					result = sendresult;
					if(sendresult != null){
						if(!sendresult.equals("") &&
								!sendresult.equals("500") && !sendresult.equals("501") &&
								!sendresult.equals("550") && !sendresult.equals("600")){
							
							int ret = 0;
							ret = workorderBean.saveSMS(msgid, mobile, "0");
							break;
						}
					}
				}
			}
			//result = "500";
			out = new OutputStreamWriter(response.getOutputStream(), "GBK");
			out.write(result);
			out.close();
			//			Map<String,List<String>> map = conn.getHeaderFields();
			//			//�������е���Ӧͷ�ֶ�
			//			for (String key : map.keySet())
			//			{
			////				if(key != null)
			////					if(key.equals("result")){
			////						System.out.println(map.get(key));
			////					}
			//			System.out.println(key + "--->" + map.get(key));
			//			}
		} catch (Exception e) {
			System.out.println("����GET��������쳣��" + e);
			e.printStackTrace();
		} finally {
			try {
				if (out != null) {
					out.close();
				}
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}

		return null;
	}
	

	public ActionForward balance(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		WorkOrderActionForm actionForm = (WorkOrderActionForm) form;

		/*
			 ����	Ҫ��	����	��ע
			user	��ѡ	�˺���	�ʺţ���Ҫ����
			pwd	��ѡ	����	��¼����
			mobile	��ѡ	�ֻ����	����Ϣ�����ֻ����50����룬Ӣ�Ķ��ŷָ�
			����POST��ʽ������û������
			message	��ѡ	�·�����Ϣ����	����Ϣ����URL���롣�����ֲ�����70���Ӣ�Ĳ�����140������Ϣ�߶���è,116���ֽ�.
			msgid	��ѡ	��Ϣ��ʶ	�Զ��壬���ڶ�ȡ��Ϣ״̬����Ϊ������Ϊ����Ҫ״̬����
			����45���ַ����ڣ�ʱ��Ϳ���
		 */
		String user = Util.filter(request.getParameter("user"));
		String pwd = Util.filter(request.getParameter("pwd"));
		String mobile = Util.filter(request.getParameter("mobile"));
		String message = Util.filter(request.getParameter("message"));
		String msgid = Util.filter(request.getParameter("msgid"));

		System.out.println("---user=" + user);
		String url = "http://127.0.0.1:8080/SMS/index.jsp?user=";
		url = WORKORDERFRAME.QUERYFEEURL + "?user=" + user + "&pwd=" + pwd;
		//		String param = "'1'";
		//		param = java.net.URLEncoder.encode(param);
		//		url = url+param;
		System.out.println("---url=" + url);
		log.info("---url=" + url);
		URLConnection conn = null;
		OutputStreamWriter out = null;
		try {
			URL realUrl = new URL(url);
			conn = realUrl.openConnection();
			conn.setRequestProperty("accept", "*/*");
			conn.setRequestProperty("connection", "Keep-Alive");
			conn.setRequestProperty("user-agent",
					"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
			conn.connect();

			String result = "";
			BufferedReader in = new BufferedReader(new InputStreamReader(conn
					.getInputStream()));
			String line;
			while ((line = in.readLine()) != null) {
				result += "\n" + line;
			}
			in.close();
			System.out.println("result=" + result);
			log.info("result=" + result);
			//result = "500";
			out = new OutputStreamWriter(response.getOutputStream(), "GBK");
			out.write(result);
			out.close();
			//			Map<String,List<String>> map = conn.getHeaderFields();
			//			//�������е���Ӧͷ�ֶ�
			//			for (String key : map.keySet())
			//			{
			////				if(key != null)
			////					if(key.equals("result")){
			////						System.out.println(map.get(key));
			////					}
			//			System.out.println(key + "--->" + map.get(key));
			//			}
		} catch (Exception e) {
			System.out.println("����GET��������쳣��" + e);
			log.info(e);
			e.printStackTrace();
		} finally {
			try {
				if (out != null) {
					out.close();
				}
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}

		return null;
	}
	
	public ActionForward querystatus(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		WorkOrderActionForm actionForm = (WorkOrderActionForm) form;

		/*
			 ����	Ҫ��	����	��ע
			user	��ѡ	�˺���	�ʺţ���Ҫ����
			pwd	��ѡ	����	��¼����
			msgid	��ѡ	��Ϣ��ʶ	�Զ��壬���ڶ�ȡ��Ϣ״̬����Ϊ������Ϊ����Ҫ״̬����
			����45���ַ����ڣ�ʱ��Ϳ���
		 */
		String user = Util.filter(request.getParameter("user"));
		String pwd = Util.filter(request.getParameter("pwd"));
		String mobile = Util.filter(request.getParameter("mobile"));
		String message = Util.filter(request.getParameter("message"));
		String msgid = Util.filter(request.getParameter("msgid"));

		System.out.println("---user=" + user);
		String url = "http://127.0.0.1:8080/SMS/index.jsp?user=";
		url = WORKORDERFRAME.QUERYSTATUSURL + "?user=" + user + "&pwd=" + pwd + "&msgid=" + msgid;
		//		String param = "'1'";
		//		param = java.net.URLEncoder.encode(param);
		//		url = url+param;
		System.out.println("---url=" + url);
		log.info("---url=" + url);
		URLConnection conn = null;
		OutputStreamWriter out = null;
		try {
			URL realUrl = new URL(url);
			conn = realUrl.openConnection();
			conn.setRequestProperty("accept", "*/*");
			conn.setRequestProperty("connection", "Keep-Alive");
			conn.setRequestProperty("user-agent",
					"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
			conn.connect();

			String result = "";
			BufferedReader in = new BufferedReader(new InputStreamReader(conn
					.getInputStream()));
			String line;
			while ((line = in.readLine()) != null) {
				result += "\n" + line;
			}
			in.close();
			System.out.println("result=" + result);
			log.info("result=" + result);
			//result = "500";
			out = new OutputStreamWriter(response.getOutputStream(), "GBK");
			out.write(result);
			out.close();
			//			Map<String,List<String>> map = conn.getHeaderFields();
			//			//�������е���Ӧͷ�ֶ�
			//			for (String key : map.keySet())
			//			{
			////				if(key != null)
			////					if(key.equals("result")){
			////						System.out.println(map.get(key));
			////					}
			//			System.out.println(key + "--->" + map.get(key));
			//			}
		} catch (Exception e) {
			System.out.println("����GET��������쳣��" + e);
			log.info(e);
			e.printStackTrace();
		} finally {
			try {
				if (out != null) {
					out.close();
				}
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}

		return null;
	}
	
	public ActionForward mo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		WorkOrderActionForm actionForm = (WorkOrderActionForm) form;

		/*
			 ����	Ҫ��	����	��ע
			circle	����	�˺���	�ַ�20λ��	
			pwd	����	����	�ַ�20λ��	
			Starttime	����	��ʼʱ��	�ַ�	�ַ�(��8λ����ʽ����ĸ�ʽ����ʽΪYYYYMMDD����14λYYYYMMDDHHMMSS)
			Endtime	����	����ʱ��	�ַ�	�ַ�(��8λ����ʽ����ĸ�ʽ����ʽΪYYYYMMDD����14λYYYYMMDDHHMMSS)

		 */
		String user = Util.filter(request.getParameter("user"));
		String pwd = Util.filter(request.getParameter("pwd"));
		String Starttime = Util.filter(request.getParameter("Starttime"));
		String Endtime = Util.filter(request.getParameter("Endtime"));

		System.out.println("---user=" + user);
		log.info("---user=" + user);
		String url = "http://127.0.0.1:8080/SMS/index.jsp?user=";
		url = WORKORDERFRAME.GETSMSYURL + "?circle=" + user + "&pwd=" + pwd + "&Starttime=" + Starttime+ "&Endtime=" + Endtime;
		//		String param = "'1'";
		//		param = java.net.URLEncoder.encode(param);
		//		url = url+param;
		System.out.println("---url=" + url);
		log.info("---url=" + url);
		URLConnection conn = null;
		OutputStreamWriter out = null;
		try {
			URL realUrl = new URL(url);
			conn = realUrl.openConnection();
			conn.setRequestProperty("accept", "*/*");
			conn.setRequestProperty("connection", "Keep-Alive");
			conn.setRequestProperty("user-agent",
					"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
			conn.connect();

			String result = "";
			BufferedReader in = new BufferedReader(new InputStreamReader(conn
					.getInputStream()));
			String line;
			while ((line = in.readLine()) != null) {
				result += "\n" + line;
			}
			in.close();
			System.out.println("result=" + result);
			log.info("result=" + result);
			//result = "500";
			out = new OutputStreamWriter(response.getOutputStream(), "GBK");
			out.write(result);
			out.close();
			//			Map<String,List<String>> map = conn.getHeaderFields();
			//			//�������е���Ӧͷ�ֶ�
			//			for (String key : map.keySet())
			//			{
			////				if(key != null)
			////					if(key.equals("result")){
			////						System.out.println(map.get(key));
			////					}
			//			System.out.println(key + "--->" + map.get(key));
			//			}
		} catch (Exception e) {
			System.out.println("����GET��������쳣��" + e);
			log.info(e);
			e.printStackTrace();
		} finally {
			try {
				if (out != null) {
					out.close();
				}
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}

		return null;
	}
	
	public ActionForward SMSStatus(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		WorkOrderActionForm actionForm = (WorkOrderActionForm) form;

		/*
			 ����	����	��ע
			msgid	����Ϣ����Ϣ��ʶ��	��Ϣ��ʶ����CP���ڷ��Ͷ���Ϣʱָ��
			mobile	�ֻ��	
			subsn	����Ϣ�������	��ֺ�Ķ���Ϣ������ţ�����һ����msgidָ���Ķ���Ϣ���ڹ�ϵͳ�Զ���ֳ��������Ϣ��ϵͳ�᷵������״̬���棬subsnȡֵ�ֱ�Ϊ1,2,3����δ��ֵĶ���Ϣ��subsn�̶�ȡֵΪ0
			status	״ֵ̬	0��ʾ�ɹ�������ֵ��ʾʧ��

		 */
		String msgid = Util.filter(request.getParameter("msgid"));
		String mobile = Util.filter(request.getParameter("mobile"));
		String subsn = Util.filter(request.getParameter("subsn"));
		String status = Util.filter(request.getParameter("status"));

//		System.out.println("---user=" + user);
//		String url = "http://127.0.0.1:8080/SMS/index.jsp?user=";
//		url = WORKORDERFRAME.SENDSMSURL + "?user=" + user + "&pwd" + pwd
//				+ "&mobile" + mobile + "&message" + message + "&msgid" + msgid;
		//		String param = "'1'";
		//		param = java.net.URLEncoder.encode(param);
		//		url = url+param;
//		System.out.println("---url=" + url);
		URLConnection conn = null;
		OutputStreamWriter out = null;
		try {
//			URL realUrl = new URL(url);
//			conn = realUrl.openConnection();
//			conn.setRequestProperty("accept", "*/*");
//			conn.setRequestProperty("connection", "Keep-Alive");
//			conn.setRequestProperty("user-agent",
//					"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
//			conn.connect();
//
			String result = "0";
			int ret = 0;
			ret = workorderBean.SMSStatus(msgid, mobile, subsn, status);
			if(ret == 0){
				result = "500";
			}
//			BufferedReader in = new BufferedReader(new InputStreamReader(conn
//					.getInputStream()));
//			String line;
//			while ((line = in.readLine()) != null) {
//				result += "\n" + line;
//			}
//			in.close();
//			System.out.println("result=" + result);
			//result = "500";
			out = new OutputStreamWriter(response.getOutputStream(), "GBK");
			out.write(result);
			out.close();
			//			Map<String,List<String>> map = conn.getHeaderFields();
			//			//�������е���Ӧͷ�ֶ�
			//			for (String key : map.keySet())
			//			{
			////				if(key != null)
			////					if(key.equals("result")){
			////						System.out.println(map.get(key));
			////					}
			//			System.out.println(key + "--->" + map.get(key));
			//			}
		} catch (Exception e) {
			System.out.println("����GET��������쳣��" + e);
			log.info(e);
			e.printStackTrace();
		} finally {
			try {
				if (out != null) {
					out.close();
				}
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}

		return null;
	}
	
	public ActionForward ReceiveSMS(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		WorkOrderActionForm actionForm = (WorkOrderActionForm) form;

		/*
			 ����	����	��ע
			mobile	�ֻ����	�û��ֻ����,С��ͨ(���+����)
			message	��Ϣ����	�û����е���Ϣ���ݵ�URL����
			gw	��ر�ʶ	cm��ʾ�ƶ���أ�un��ʾjͨ��ء�cn��ͨ��ct����
			spnumber	�ط���	�û����е��ط���620129230025****0001
			cell	С��	�û����е�С���� 0001


		 */
		String mobile = Util.filter(request.getParameter("mobile"));
		String message = Util.filter(request.getParameter("message"));
		String gw = Util.filter(request.getParameter("gw"));
		String spnumber = Util.filter(request.getParameter("spnumber"));
		String cell = Util.filter(request.getParameter("cell"));

		URLConnection conn = null;
		OutputStreamWriter out = null;
		try {

			String result = "0";
			int ret = 0;
			ret = workorderBean.ReceiveSMS(mobile, message, gw, spnumber, cell);
			if(ret == 0){
				result = "500";
			}
			out = new OutputStreamWriter(response.getOutputStream(), "GBK");
			out.write(result);
			out.close();
			
		} catch (Exception e) {
			System.out.println("����GET��������쳣��" + e);
			log.info(e);
			e.printStackTrace();
		} finally {
			try {
				if (out != null) {
					out.close();
				}
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}

		return null;
	}

	public ActionForward test(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		WorkOrderActionForm actionForm = (WorkOrderActionForm) form;

		String user = Util.filter(request.getParameter("user"));
		String pwd = Util.filter(request.getParameter("pwd"));
		String mobile = Util.filter(request.getParameter("mobile"));
		String message = Util.filter(request.getParameter("message"));
		String msgid = Util.filter(request.getParameter("msgid"));

		System.out.println("user=" + user);
		log.info("user=" + user);

		return null;
	}
	
	public ActionForward ReceiverMO(ActionMapping mapping, ActionForm form,
			HttpServletRequest req, HttpServletResponse resp)
			 {
		try {
		System.out.println("---------------------------------------------");
		String spid = req.getParameter("spid");
        String momsgid = req.getParameter("momsgid");
        String da = req.getParameter("da");
        String sa = req.getParameter("sa");
        String dc = req.getParameter("dc");
        String sm = req.getParameter("sm");
        System.out.println(req.getQueryString());
        //将Hex编码的上行内容还原成普通字符串
        //在jdk1.4版本环境下，请使用DIYClientExample.decodeHexStr(Integer.parseInt(dc),sm)
        String moContent = "";
        try {
        	moContent = SimpleClientExample.decodeHexStr(Integer.parseInt(dc),sm);     
        } catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        System.out.println(sa);
        log.info(sa);
        System.out.println(da);
        log.info(da);
        System.out.println(moContent);
        log.info(moContent);
        
        //获取上行参数后，请即刻返回响应信息
        PrintWriter pw;
		
			pw = resp.getWriter();
		
        StringBuilder output = new StringBuilder();
        output.append("command=MO_RESPONSE&spid=");
        output.append(spid);
        output.append("&momsgid=");
        output.append(momsgid);
        output.append("&mostat=ACCEPT&moerrcode=000");
        resp.setContentLength(output.length());
        pw.write(output.toString());
        pw.flush();
        pw.close();

        //处理逻辑
        System.out.println(sa);
        log.info(sa);
        System.out.println(da);
        log.info(da);
        System.out.println(moContent);
        log.info(moContent);
        /*
         process code
         ......
         */
		String sql = "insert into documentin (Documentin_GUID, DocType,Status,  DocumentPath, DocumentFrom, DocumentTo, ModifiedBy, ModifiedDate)"
+	" values(Sys_Guid(), 3, 0,  '"+Util.filter(moContent)+"', '"+Util.filter(sa)+"', '"+Util.filter(da)+"', 'elite', sysdate) ";
		workorderBean.insertinto(sql);
        } catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	
	public ActionForward TS_QueryUndwrtStatus(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.info("开始进入TS_QueryUndwrtStatus:");
		WorkOrderActionForm actionForm = (WorkOrderActionForm) form;
		String QueryUndwrtInputDto = Util.filter(request.getParameter("QueryUndwrtInputDto"));
		log.info("QueryUndwrtInputDto:"+QueryUndwrtInputDto);
		
		
		//PrintWriter writer = response.getWriter();
		StringBuffer sb = new StringBuffer();
		//String xml = null;
		String line = null;
		
		BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream()));
		while ((line = in.readLine()) != null) {
			sb.append(line);
		}
		System.out.println("BufferedReader in="+sb.toString());
		log.info("BufferedReader in="+sb.toString());
		QueryUndwrtInputDto = sb.toString();
		System.out.println("QueryUndwrtInputDto="+QueryUndwrtInputDto);
		log.info("QueryUndwrtInputDto="+QueryUndwrtInputDto);
		//QueryUndwrtInputDto = "<?xml version='1.0' encoding='gb2312'?><QueryUndwrtInputDto><ProposalNo>2028910042010000107</ProposalNo><ProposalStatus>05</ProposalStatus><Underwriteopinion>ͬ��</Underwriteopinion></QueryUndwrtInputDto>";
		
		URLConnection conn = null;
		OutputStreamWriter out = null;
		try {
			String ProposalNo = "";
			String ProposalStatus = "";
			String Underwriteopinion = "";
			String UnderwriteDate = "";
			
			Document document = DocumentHelper.parseText(QueryUndwrtInputDto);
			Element root = document.getRootElement();
//			for (Iterator it = root.elementIterator("QueryUndwrtInputDto"); it.hasNext();) {
				Element element = root;//(Element) it.next();
				ProposalNo = element.elementText("ProposalNo");
				ProposalStatus = element.elementText("ProposalStatus");
				Underwriteopinion = element.elementText("Underwriteopinion");
				UnderwriteDate = element.elementText("UnderwriteDate");
				System.out.println("ProposalNo="+ProposalNo);
				log.info("ProposalNo="+ProposalNo);
				System.out.println("ProposalStatus="+ProposalStatus);
				log.info("ProposalStatus="+ProposalStatus);
				System.out.println("Underwriteopinion="+Underwriteopinion);		
				log.info("Underwriteopinion="+Underwriteopinion);
				System.out.println("UnderwriteDate="+UnderwriteDate);	
				log.info("UnderwriteDate="+UnderwriteDate);
//			}
			
			String result = "1";
			int ret = 0;
			ret = workorderBean.TS_QueryUndwrtStatus(ProposalNo, ProposalStatus, Underwriteopinion, UnderwriteDate);
			if(ret == 0){
				result = "2";
			}
			//result = "500";
			
			request.setAttribute("result", result);
			log.info("request="+request);
		} catch (Exception e) {
			System.out.println("����GET��������쳣��" + e);
			log.info("TS_QueryUndwrtStatus错误="+e);
			e.printStackTrace();
			String result = "2";
			log.info("request="+request);
			request.setAttribute("result", result);
		} finally {
			try {
				if (out != null) {
					out.close();
				}
			} catch (IOException ex) {
				ex.printStackTrace();
				log.info("IOException");
			}
		}
		log.info("TS_QueryUndwrtStatus调用结束");
		return mapping.findForward("dealwp");
	}
	
	public String inquerystatus(String user, String pwd, String msgid)
			throws Exception {

		/*
			 ����	Ҫ��	����	��ע
			user	��ѡ	�˺���	�ʺţ���Ҫ����
			pwd	��ѡ	����	��¼����
			msgid	��ѡ	��Ϣ��ʶ	�Զ��壬���ڶ�ȡ��Ϣ״̬����Ϊ������Ϊ����Ҫ״̬����
			����45���ַ����ڣ�ʱ��Ϳ���
		 */
		
		String result = "";
		
		System.out.println("---user=" + user);
		log.info("---user=" + user);
		String url = "http://127.0.0.1:8080/SMS/index.jsp?user=";
		url = WORKORDERFRAME.QUERYSTATUSURL + "?user=" + user + "&pwd=" + pwd + "&msgid=" + msgid;
		//		String param = "'1'";
		//		param = java.net.URLEncoder.encode(param);
		//		url = url+param;
		System.out.println("---url=" + url);
		log.info("---url=" + url);
		URLConnection conn = null;
		OutputStreamWriter out = null;
		try {
			URL realUrl = new URL(url);
			conn = realUrl.openConnection();
			conn.setRequestProperty("accept", "*/*");
			conn.setRequestProperty("connection", "Keep-Alive");
			conn.setRequestProperty("user-agent",
					"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
			conn.connect();

			BufferedReader in = new BufferedReader(new InputStreamReader(conn
					.getInputStream()));
			String line;
			while ((line = in.readLine()) != null) {
				result += "\n" + line;
			}
			in.close();
			System.out.println("result=" + result);
			log.info("result=" + result);
			//result = "500";
			
		} catch (Exception e) {
			System.out.println("����GET��������쳣��" + e);
			log.info(e);
			e.printStackTrace();
		} finally {
			try {
				if (out != null) {
					out.close();
				}
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}

		return result;
	}

}
